package com.lfy.controller;

import com.lfy.aop.Limiting;
import com.lfy.annotation.Log;
import com.lfy.aop.LimitingTest;
import com.lfy.aop.LimitingTestTow;
import com.lfy.domian.EF;
import com.lfy.domian.FactoryUtil;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@RestController
public class LimitController {
    @Resource
    ApplicationEventPublisher applicationEventPublisher;

    @GetMapping("/limit")
    @Limiting(time = 10, num = 3,TIME_UNIT = TimeUnit.SECONDS)
    public String limit(){

        return "ok";
    }
    @GetMapping("/limitday")
    @Limiting(time = 1, num = 20,TIME_UNIT = TimeUnit.DAYS)
    public String limitday(){
        return "ok";
    }

    @GetMapping("/blog")
    @Limiting(time = 10,num = 4,TIME_UNIT = TimeUnit.SECONDS)
    public String blogTest(@RequestParam("testName") String testName, @RequestParam("testArg") String testArg){
        return "ok";
    }
    @GetMapping("/new")
    public String newBlog(@RequestParam("testName") String testName, @RequestParam("testArg") String testArg){
        return "ok";
    }
    @GetMapping("/newa")
    @Log("testtt")
    public String Log(){
        return "ok";
    }
    @GetMapping("/u")
    public String u(){
        DefaultListableBeanFactory defaultListableBeanFactory = new DefaultListableBeanFactory(new DefaultListableBeanFactory());
        EF bean = defaultListableBeanFactory.getBean(EF.class);
        System.out.println(bean);
        return "ok";
    }
    @GetMapping("/ua")
    @LimitingTest("321")
    public String ua(){

        return "ok";
    }

    @GetMapping("/uaa")
    @LimitingTestTow(value = "a321")
    public String uaa(){

        return "ok";
    }
}
